// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import Character from "../../TS/BASE/Character";
import DES from "../../TS/Ditu/des/DES";
import GeZiManager from "../../TS/Manager/GeZiManager";
import { Message } from "../../TS/Message/Message";
import MessageCenter from "../../TS/Message/MessageCenter";
import { SHMessage } from "../../TS/Message/SHMessage";
import SXX from "../../TS/Scharacter/SXX";
import { FDUI } from "../../TS/UIS/else/FDUI";

const {ccclass, property} = cc._decorator;

@ccclass
export default class qizi extends DES {
color:string="Blue"
FW: number[]=[];
tt:string="flag"
FZ(){

setTimeout(()=>{
this.node.children[0].getComponent(sp.Skeleton).animation="Idle"
this.node.children[1].getComponent(sp.Skeleton).animation="Idle"
this.node.children[2].getComponent(sp.Skeleton).animation="Idle"
},700)

this.node.children[0].getComponent(sp.Skeleton).loop=true
this.node.children[1].getComponent(sp.Skeleton).loop=true
this.node.children[2].getComponent(sp.Skeleton).loop=true






switch (this.color) {
    case "Blue":this.node.children[1].active=true;for(let a of this.getNIG(this.ZB)){  GeZiManager.redM.push(a)}
  
        
        break;
        case "Red":this.node.children[0].active=true;for(let a of this.getNIG(this.ZB)){  GeZiManager.blueM.push(a)}
        
        break;
        case "S02":this.node.children[2].active=true
        
        break;
    default:
        break;
}
for (let index = 1; index <= 9; index++) {
    this.FW.push(this.findGe(index,1))
    
}
GeZiManager.Tcharacters=[];
MessageCenter.MakeSHMessage("AM",this.FW,1,0,"getOnes")

for(let a of  GeZiManager.Tcharacters){
    if(a!=null&&a instanceof Character)  {
if(a.color!=this.color&&this.color!="S02"){

   // a.turnBan[2]=100
    console.log(a.Pturn)
  // a.ST();
}
if (this.color=="S02"&&a.node.getComponent(SXX).Snumber!="S02") {
  //if (a.S02==0) {
    
    //for (let index = 0; index <= a.TNJJ.length-1; index++) {
     //   a.TNJJ[index]++
          
     // }
 // }
  
 
   // a.S02+=1




   a.turnBan[2]=100

  a.ST();
}



}

}

}
ObstacleClear()//清除当前坐标障碍物
{
    for (let i = GeZiManager.AllObstacles.length - 1; i >= 0; i--) {
        if (GeZiManager.AllObstacles[i].ZB === this.ZB) {
            GeZiManager.AllObstacles.splice(i, 1);
        }
    }
}








BZ(preZB:number)
{


    












    MessageCenter.MakeSHMessage("AM",[this.ZB],1,0,"getOneC")
if (!GeZiManager.Tcharacter) {
    GeZiManager.Tcharacter=this
}
if (this.color=="null") {
    this.ObstacleClear()
   // MessageCenter.MakeGMessage("AM",[this.ZB,99],8,1,"FTP");
}
    if((GeZiManager.Tcharacter&&GeZiManager.Tcharacter.color!=this.color&&this.color!="S02")||(this.color=="S02"&&GeZiManager.Tcharacter.node.getComponent(SXX).Snumber!="S02"))
    {
        this.node.children[0].getComponent(sp.Skeleton).animation="break"
    this.node.children[1].getComponent(sp.Skeleton).animation="break"
    this.node.children[2].getComponent(sp.Skeleton).animation="break"
this.node.children[3].active=false
this.node.children[0].getComponent(sp.Skeleton).loop=false
this.node.children[1].getComponent(sp.Skeleton).loop=false
this.node.children[2].getComponent(sp.Skeleton).loop=false
        
        
switch (this.color) {
    case "Blue":this.node.children[1].active=true;for(let a of this.getNIG(this.ZB)){ GeZiManager.shanchu(GeZiManager.redM,a) }
  
        
        break;
        case "Red":this.node.children[0].active=true;for(let a of this.getNIG(this.ZB)){ GeZiManager.shanchu(GeZiManager.blueM,a)}
        
        break;
        case "S02":this.node.children[2].active=true
        
        break;
    default:
        break;
}     
        
        
        
        
        
        
        
        
        
        
        
        if (this.color=="S02") {
       // MessageCenter.MakeSHMessage("AM",[this.ZB],1,GeZiManager.Tcharacter.Pturn,"TN+")
       
    }else{       MessageCenter.MakeSHMessage("AM",[this.ZB],1,GeZiManager.Tcharacter.Pturn,"Qi+")

    }

       this.ObstacleClear()
      setTimeout(()=>{this.fadeOutAndDisappear(this.node,900)}) 
    
    GeZiManager.Tcharacters=[];
    MessageCenter.MakeSHMessage("AM",this.FW,1,0,"getOnes")
 
    for(let a of  GeZiManager.Tcharacters){
        if(a!=null&&a instanceof Character)  {
    if(a.color!=this.color&&this.color!="S02"){
    
      //  a.turnBan[2]=0
        

    }
    
    if(this.color=="S02"&&a.node.getComponent(SXX).Snumber!="S02"&&a.S02!=0&&GeZiManager.Tcharacter.qi!=0){
        a.turnBan[2]=0

         
         
        }
a.ST();
    }
}
this.color="dead"

}


this.node.removeComponent(FDUI)
GeZiManager.Tcharacter=null
}








LK(ZB:number){
/*
    MessageCenter.MakeSHMessage("AM",[ZB],1,0,"getOneC")
    if(GeZiManager.Tcharacter&&GeZiManager.Tcharacter instanceof Character){
 if(GeZiManager.Tcharacter.color!=this.color&&this.color!="S02"){

        GeZiManager.Tcharacter.turnBan[2]=0
        GeZiManager.Tcharacter.ST();

    }

if (this.color=="S02"&&GeZiManager.Tcharacter.node.getComponent(SXX).Snumber!="S02"&&GeZiManager.Tcharacter.S02!=0&&GeZiManager.Tcharacter.qi!=0) {
    GeZiManager.Tcharacter.S02-=1
        if (GeZiManager.Tcharacter.S02==0) {
    for (let index = 0; index <= GeZiManager.Tcharacter.TNJJ.length-1; index++) {
        GeZiManager.Tcharacter.TNJJ[index]--
           
       } 
    console.log(GeZiManager.Tcharacter.TNJJ)
    GeZiManager.Tcharacter.ST();
}

}
}}*/


MessageCenter.MakeSHMessage("AM",[ZB],1,0,"getOneC")
if(GeZiManager.Tcharacter&&GeZiManager.Tcharacter instanceof Character){
if(GeZiManager.Tcharacter.color!=this.color&&this.color=="S02"){
    GeZiManager.Tcharacter.turnBan[2]=0

    GeZiManager.Tcharacter.ST();

}}




}
JR(ZB:number){
  /*  MessageCenter.MakeSHMessage("AM",[ZB],1,0,"getOne")
 

if(GeZiManager.Tcharacter!=null&&GeZiManager.Tcharacter instanceof Character){

    if(GeZiManager.Tcharacter.color!=this.color&&this.color!="S02"){

       GeZiManager.Tcharacter.turnBan[2]=100
       
       GeZiManager.Tcharacter.ST();
       
   }

   if (this.color=="S02"&&GeZiManager.Tcharacter.node.getComponent(SXX).Snumber!="S02"&&GeZiManager.Tcharacter.qi!=0) {
   
   if (GeZiManager.Tcharacter.S02==0) {
    for (let index = 0; index <=GeZiManager.Tcharacter.TNJJ.length-1; index++) {
        GeZiManager.Tcharacter.TNJJ[index]++;
        
    }
   }
    
    GeZiManager.Tcharacter.S02+=1
    console.log(GeZiManager.Tcharacter.TNJJ)
    GeZiManager.Tcharacter.ST();
}

}*/

MessageCenter.MakeSHMessage("AM",[ZB],1,0,"getOneC")
if(GeZiManager.Tcharacter&&GeZiManager.Tcharacter instanceof Character){
if(GeZiManager.Tcharacter.color!=this.color&&this.color=="S02"){
    GeZiManager.Tcharacter.turnBan[2]=100
       
    GeZiManager.Tcharacter.ST();

}}



}

ReceiveMessage(message: SHMessage): void {
 
  if(this.color!="dead") {
    switch (message.SHtype) {
        case "wind":this.node.children[0].getComponent(sp.Skeleton).animation="Wind";this.node.children[1].getComponent(sp.Skeleton).animation="Wind"
            setTimeout(() => {
                this.node.children[0].getComponent(sp.Skeleton).animation="Idle";this.node.children[1].getComponent(sp.Skeleton).animation="Idle"
            }, 2000);
            break;
    case "mofa": if(this.ZB==message.Command[0]){this.BZ(this.ZB)
        
    }
    break;
        default:
            break;
    }}
}









  
}
